                                                              
                                                                     
                                                                     
                                             
package util;

public final class IpAdressChecker
{
	public static boolean ipChecker(String ipAdress)
	{
		boolean ip = true;
		
		//Check that the address has the correct length
		if(ipAdress.length()>=7 && ipAdress.length()<=15)
		{
			//Check that the address has the correct number of points
			for(int i=0,j=0; i<=ipAdress.length()-1 && ip==true; i++)
			{
				if(ipAdress.charAt(i) == '.')
					j++;
				if(j>3)
					ip=false;
			}
			
			//Check that the points are in the right place
			for(int i=0,j=0; i<=ipAdress.length()-1 && ip==true; i++)
			{
				if(ipAdress.charAt(i)=='.' && j>0 && j<=3)
					j=0; else j++;
				if(j>3)
					ip=false;
			}
			
			//Check that everything else is in place
			for(int i=0, j=0; i<=ipAdress.length()-1 && ip==true; i++)
			{
				if(i!=j)
					ip = false;
				
				switch(ipAdress.charAt(i))
				{
				case '0': j++; break;
				case '1': j++; break;
				case '2': j++; break;
				case '3': j++; break;
				case '4': j++; break;
				case '5': j++; break;
				case '6': j++; break;
				case '7': j++; break;
				case '8': j++; break;
				case '9': j++; break;
				case '.': j++;break;
				}
			}
		} else ip = false;
		
		//Check if ip value si not over 255.255.255.255
		if(ip==true && (255 < new Integer(ipAdress.split("\\.")[0]).intValue()
				|| 255 < new Integer(ipAdress.split("\\.")[1]).intValue()
				|| 255 < new Integer(ipAdress.split("\\.")[2]).intValue()
				|| 255 < new Integer(ipAdress.split("\\.")[3]).intValue()))
			ip = false;
		
		return ip;
	}
}